<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var str = 'abcdacbabcbababcbabcabd';
        var res1 = 0,res2 = 0,res3 = 0,res4 = 0;
        for(var i = str.length - 1; i >= 0 ; i--){
            if(str[i] === 'a'){
                res1 += 1;
            }else if(str[i] === 'b'){
                res2 += 1;
            }else if(str[i] === 'c'){
                res3 += 1;
            }else if(str[i] === 'd'){
                res4 += 1;
            }
        }
       console.log(res1,res2,res3,res4);
       
        
    </script>
</body>
</html>